package cn.net.yugu.doraemon.netty.protocol.msg05;

import cn.net.yugu.doraemon.netty.msg.TypeOperator;
import cn.net.yugu.doraemon.netty.protocol.MsgCode;
import io.netty.buffer.ByteBuf;

/**
 * 电池心跳
 */
public class Msg052000001 extends Msg052 {
    public String code;
    public byte commType;
    public long requestTime;
    public Data data = new Data();

    public static class Data extends TypeOperator {
        public int msgCode;
        public int time;
        public int serial;
        public String body;

        public void read(ByteBuf buf) {
            msgCode = buf.readInt();
            time = buf.readInt();
            serial = buf.readInt();
            body = readString(buf);
        }

        public void write(ByteBuf buf) {
            buf.writeInt(msgCode);
            buf.writeInt(time);
            buf.writeInt(serial);
            writeString(buf, body);
        }
    }

    @Override
    public int getMsgCode() {
        return MsgCode.MSG_052000001.getCode();
    }

    @Override
    public void readData(ByteBuf buffer) {
        code = readString(buffer);
        commType = buffer.readByte();
        requestTime = buffer.readLong();
        data.read(buffer);
    }

    @Override
    public void writeData(ByteBuf buffer) {
        writeString(buffer, code);
        buffer.writeByte(commType);
        buffer.writeLong(requestTime);
        data.write(buffer);
    }
}
